package a_o2odata_deal.utils.zhibo_zf

import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.sql.SQLContext

/**
  * @ Auther: o2o-rd-0008
  * @ Date:   2020/1/14 11:27
  * @ Param:  ${PARAM}
  * @ Description: 
  */
object handle_zbjg {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
    conf.setAppName(s"${this.getClass.getSimpleName}")
    conf.set("spark.debug.maxToStringFields", "500")
    conf.setMaster("local[*]")
    conf.set("es.nodes", "192.168.1.157")
    conf.set("es.port", "9200")
    conf.set("cluster.name", "O2OElastic")
    conf.set("spark.serializer", "org.apache.spark.serializer.KryoSerializer")
    conf.set("spark.sql.caseSensitive", "true")
    val sc = new SparkContext(conf)
    val sqlContext = new SQLContext(sc)
    sc.setLogLevel("WARN")
    sc.hadoopConfiguration.set("fs.s3a.access.key", "GAO7EO9FWKPJ8WFCQDME")
    sc.hadoopConfiguration.set("fs.s3a.secret.key", "LZ0xaHBSYKHaJ9ECDbX9f7zin79UZkXfGoNapRPL")
    sc.hadoopConfiguration.set("fs.s3a.endpoint", "https://obs.cn-north-1.myhuaweicloud.com")

    //加载数据
    val ali_store = sqlContext.read.json(a_aa_amainpackage.a_o2odata_deal.config.config.ali_store_path)
      .dropDuplicates("affiliateId")
    //val ali_zb = sqlContext.read.json(a_aa_amainpackage.a_o2odata_deal.config.config.ali_zb_path)
    val ali_store_address_all = sqlContext.read.json(a_aa_amainpackage.a_o2odata_deal.config.config.ali_store_address_all_path)
      .dropDuplicates("shopId")

    ali_store.createOrReplaceTempView("ali_store")
    ali_store_address_all.createOrReplaceTempView("ali_store_address_all")

    sqlContext.sql(
      s"""
         |select
         |--机构ID
         |t1.affiliateId,
         |--机构名称
         |t1.affiliate,
         |--合作任务数
         |t1.taskNumber,
         |--签约主播数
         |t1.darenCount,
         |--所属地区
         |case when t2.shopId is null then '-1' else t2.province end as province,
         |case when t2.shopId is null then '-1' else t2.city end as city,
         |case when t2.shopId is null then '-1' else t2.county end as district,
         |case when t2.shopId is null then '-1' else t2.regional_ID end as regional_ID,
         |--所属企业
         |case when t2.shopId is null then '0' else t2.tianyancha_company_name end as company_name
         |from ali_store t1
         |left join
         |ali_store_address_all t2
         |on t1.affiliateId=t2.shopId
       """.stripMargin).repartition(4).write.orc(s"s3a://o2o-dataproces-group/panzonghao/zhibo_zf/2020/1/zhibojigou")


  }

}
